package com.gitee.wsl.ext.string

import kotlin.math.min

fun compareCharacterSequences(seq1: CharSequence, seq2: CharSequence): Int {
    val len1 = seq1.length
    val len2 = seq2.length

    var i = 0
    val len = min(len1, len2)
    while (i < len) {
        val ch1 = seq1[i]
        val ch2 = seq2[i]
        if (ch1 != ch2) {
            return ch1.code - ch2.code
        }
        i++
    }
    return len1 - len2
}